﻿<?
	
	// test
//	$user_id = 2;
//	$book_id = 1;

// Recived parameter:
// - user_id (int)
// - book_id (int)


	$user_id = $_GET['user_id'];
	$book_id = $_GET['book_id'];

	$dbh = new PDO('mysql:host=localhost;dbname=sbdb', 'root', 'winwinwin');

	if(verifyUserIDAndBookID($dbh,$user_id,$book_id))
	{ // ok
		$dbh->exec("SET NAMES UTF8");
		$str_ret = "";
		foreach($dbh->query('select book_name, book_desc, book_page_src, book_binder_src, book_bg_src from tblbook_data where book_id='.$book_id ) as $rowinner)
		{

			echo urlencode($rowinner['book_name']).",".
			urlencode($rowinner['book_desc']).",".
			urlencode($rowinner['book_page_src']).",".
			urlencode($rowinner['book_binder_src']).",".
			urlencode($rowinner['book_bg_src']);
		}
		//echo $str_ret
	}
	else{ // error
		echo "<error> Book_id: ".$book_id ." doesn't exist on user_id: ".$user_id . " </error>";
	}
	
	

	// verify that does this user have this book_id or not
	function verifyUserIDAndBookID($dbh,$user_id,$book_id)
	{
		foreach($dbh->query('select count(*) as num from tblbook_id where user_id='.$user_id. ' and book_id='.$book_id) as $row)
		{
			if($row['num'] == 1)
				return true;
			else
				return false;
		}
	}
?>
